package web.suzy.oj.utils;

/**
 * YangSuzy 软件工作室
 * 类名: Constants
 * 描述: 常量枚举类
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/9 23:31
 */
public class Constants {
    /**
     * 测评模式
     */
    public enum JudgeMode {
        /**
         * 默认判题
         */
        DEFAULT("default"),
        /**
         * 特殊判题
         */
        SPJ("spj"),
        /**
         * 交互式判题
         */
        INTERACTIVE("interactive");

        private final String mode;

        JudgeMode(String mode) {
            this.mode = mode;
        }

        public String getMode() {
            return mode;
        }

        public static JudgeMode getJudgeMode(String mode) {
            for (JudgeMode judgeMode : JudgeMode.values()) {
                if (judgeMode.getMode().equals(mode)) {
                    return judgeMode;
                }
            }
            return null;
        }
    }

    /**
     * 测评类型：ACM or OI
     */
    public enum Type {
        TYPE_ACM(0, "ACM"),
        TYPE_OI(1, "OI");
        private final Integer code;
        private final String name;

        Type(Integer code, String name) {
            this.code = code;
            this.name = name;
        }

        public Integer getCode() {
            return code;
        }

        public String getName() {
            return name;
        }
    }

    /**
     * 测试用例模式
     */
    public enum JudgeCaseMode {
        /**
         * 默认全部测评
         */
        DEFAULT("default"),
        /**
         * 求子任务组中的最低分
         */
        SUBTASK_LOWEST("subtask_lowest"),
        /**
         * 求子任务组中的平均分
         */
        SUBTASK_AVERAGE("subtask_average"),
        /**
         * 遇到错误时停止测评
         */
        ERGODIC_WITHOUT_ERROR("ergodic_without_error");

        private final String mode;

        JudgeCaseMode(String mode) {
            this.mode = mode;
        }

        public String getMode() {
            return mode;
        }


        public static JudgeCaseMode getJudgeCaseMode(String mode) {
            for (JudgeCaseMode judgeCaseMode : JudgeCaseMode.values()) {
                if (judgeCaseMode.getMode().equals(mode)) {
                    return judgeCaseMode;
                }
            }
            return DEFAULT;
        }
    }

    /**
     * 账户相关常量
     */
    public enum Account {
        CODE_CHANGE_PASSWORD_FAIL("change-password-fail:"),
        CODE_CHANGE_PASSWORD_LOCK("change-password-lock:"),
        CODE_ACCOUNT_LOCK("account-lock:"),
        CODE_CHANGE_EMAIL_FAIL("change-email-fail:"),
        CODE_CHANGE_EMAIL_LOCK("change-email-lock:"),

        TRY_LOGIN_NUM("try-login-num:"),

        ACM_RANK_CACHE("acm_rank_cache"),
        OI_RANK_CACHE("oi_rank_cache"),

        SUPER_ADMIN_UID_LIST_CACHE("super_admin_uid_list_case"),

        SUBMIT_LOCK("submit_lock:"),
        TEST_JUDGE_LOCK("test_judge_lock:"),
        DISCUSSION_ADD_NUM_LOCK("discussion_add_num_lock:");

        private final String code;

        Account(String code) {
            this.code = code;
        }

        public String getCode() {
            return code;
        }
    }

    /**
     * 文件操作常量
     */
    public enum File {


        USER_AVATAR_FOLDER("/suzyoj/file/avatar"),

        HOME_CAROUSEL_FOLDER("/suzyoj/file/carousel"),

        MARKDOWN_FILE_FOLDER("/suzyoj/file/md"),

        PROBLEM_FILE_FOLDER("/suzyoj/file/problem"),

        IMG_API("/api/public/img/"),

        FILE_API("/api/public/file/"),

        TESTCASE_TMP_FOLDER("/suzyoj/file/zip"),

        TESTCASE_BASE_FOLDER("/suzyoj/testcase"),

        FILE_DOWNLOAD_TMP_FOLDER("/suzyoj/file/zip/download");

        private final String path;

        File(String path) {
            this.path = path;
        }

        public String getPath() {
            return path;
        }
    }

    /**
     * 邮箱常量
     */
    public enum Email {

        OJ_URL("OJ_UR"),
        OJ_NAME("OJ_NAME"),
        OJ_SHORT_NAME("OJ_SHORT_NAME"),
        EMAIL_FROM("EMAIL_FROM"),
        EMAIL_BACKGROUND_IMG("EMAIL_BACKGROUND_IMG"),
        REGISTER_KEY_PREFIX("register-user:"),
        RESET_PASSWORD_KEY_PREFIX("reset-password:"),
        RESET_EMAIL_LOCK("reset-email-lock:"),
        REGISTER_EMAIL_LOCK("register-email-lock:");

        private final String value;

        Email(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }
    }
}
